<template>
	<view class="leave_box">
    <navTitle :title="'詳情'" :titleRight="''"></navTitle>
    <view class="l-container">
      <view class="d-box">
        <view class="d-t">
          <view class="d-t-l">
            <view class="l-txt">{{userInfo.nickname}}提交的請假</view>
            <view>{{ company_name }}</view>
          </view>
          <view class="d-t-r"><text :class="detailObj.status==0?'blue':detailObj.status==1?'green':'red'">{{ detailObj.status==0?'正在審批':detailObj.status==1?'審批通過':'審批未通過' }}</text></view>
        </view>
        <view class="d-steps">
          <view class="d-s-title">{{ detailObj.type_txt }} {{ detailObj.hours }}{{ detailObj.hours_unit==1?'天':'小时' }}</view>
          <uni-steps :options="steps" active-color="#007AFF" :active="stepsCurrent" direction="column" />
        </view>
        <view class="d-title">請假事由</view>
        <view class="d-txt">{{ detailObj.description }}</view>
        <view class="d-title" v-if="imgList.length>0">上傳圖片</view>
        <view class="d-imgs" v-if="imgList.length>0">
          <view class="d-img" v-for="(item,index) in imgList" :key="index" @tap="handlePreview(item,index)">
            <img :src="item" mode="scaleToFill" alt="">
          </view>
        </view>
      </view>
      <view class="d-box" v-if="false">
        <view class="b-title">審批流程</view>
        <view class="b-steps">
          <view class="b-s-item-l">
            <uni-steps :current="bCurrent" direction="column" :options="stepsList" activeColor="#1C7AF7" mode="dot"></uni-steps>
          </view>
          <view class="b-s-item-c">
            <view>赫鳴樂<text>08.15 16:37</text></view>
            <view>冶裕振<text>08.15 16:37</text></view>
            <view>懷良慶<text>08.15 16:37</text></view>
          </view>
          <view class="b-s-item-r">
            <view></view>
            <view>已同意</view>
            <view class="active">正在審批</view>
          </view>
        </view>
      </view>
    </view>
    <view class="nav-footer" v-if="detailObj.status==0">
      <view class="item-footer" @tap="jumpEdit()">
        <img src="/static/images/boss/icon_b_qj_edit.png" mode="scaleToFill" alt="">
        <view>修改</view>
      </view>
      <view class="item-footer" @tap="jumpRevoke()">
        <img src="/static/images/boss/icon_b_qj_back.png" mode="scaleToFill" alt="">
        <view>撤销</view>
      </view>
    </view>
	</view>
</template>

<script>
import { askleaveDetail,askleaveCancel } from '../../utils/api'
import navTitle from './components/nav-title.vue';
export default {
	components: {navTitle},
	data() {
		return {
      id:0,
      detailObj:{},
      userInfo:{},
      stepsCurrent:-1,
      steps: [
				{
					title: '2024-08-16 09:00'
				},
				{
					title: '2024-08-16 18:00'
				}
			],
      bCurrent:3,
      company_name:'',
      stepsList: [
				{
					name: '發起申請：'
				},
				{
					name: '直接主管：'
				},
				{
					name: '總經理：'
				}
			],
      imgList:[],
		};
	},
	props: {
		couponList: {}
	},
	computed: {},
  onShow() {
    this.userInfo=uni.getStorageSync('userInfo')
  },
  onLoad(options) {
    this.id=parseInt(options.id)
    if(this.id){
      this.getDetail()
    }
  },
	methods: {
    jumpRevoke(){
      let that=this
      uni.showModal({
        title: '提示',
        content: `確定撤銷請假申請嗎？`,
        success: res => {
          that.revokeForm()
        }
      })
    },
    async revokeForm(){
      let that=this
      let res=await askleaveCancel({id:that.detailObj.id})
      if(res.code==1){
        uni.navigateBack()
      }else{
        uni.showToast({
          icon:'none',
          title: res.msg||'系統異常'
        })
      }
    },
    jumpEdit(){
      uni.navigateTo({ url: `/pages/boss/leaveEdit?id=${this.detailObj.id}` })
    },
    handlePreview(item,index){
      uni.previewImage({
        current:index,
        urls:this.imgList
      })
    },
    async getDetail(){
      let res=await askleaveDetail({id:this.id})
      if(res.code==1){
        this.detailObj=res.data
        let imgList=res.data.image?res.data.image.indexOf(',')>0?res.data.image.split(','):[res.data.image]:[]
        this.imgList=imgList.map(v=>{
          return `${v}`
        })
        this.company_name=res.data.company.company_name
        this.steps=[
          {title:res.data.begin_time_text},
          {title:res.data.end_time_text}
        ]
      }else{
        uni.showToast({
          icon:'none',
          title: res.msg||'系統異常'
        })
      }
    }
	}
};
</script>
<style lang="scss" scoped>
.leave_box{
  width: 100%;
  height: 100vh;
  overflow-y: scroll;
  background: #F4F6FA;
}
.l-container{
  height: calc(100% - 94px);
  overflow-y: scroll;
}
.d-box{
  width: calc(100% - 40px);
  padding: 15px 10px 20px;
  background: #fff;
  border-radius: 10px;
  margin: 10px auto 10px;
}
.d-t{
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.d-t-l{
  flex: 1;
  font-size: 14px;
  color: #999999;
  line-height: 14px;
  .l-txt{
    font-weight: bold;
    font-size: 16px;
    color: #333333;
    line-height: 23px;
    padding-bottom: 10px;
  }
}
.d-t-r{
  flex: 1;
  font-weight: bold;
  font-size: 15px;
  line-height: 14px;
  text-align: right;
  .blue{
    color: #1C7AF7;
  }
  .green{
    color: #1EB50F;
  }
  .red{
    color: #DD2727;
  }
}
::v-deep .d-steps{
  padding: 12px 10px 0 10px;
  border-radius: 10px;
  margin: 12px auto 0;
  background: #F4F6FA;
  .uni-steps__column-text{
    border-bottom: none;
  }
}
.d-s-title{
  font-weight: bolder;
  font-size: 15px;
  color: #333333;
  line-height: 23px;
}
.d-title{
  font-size: 14px;
  color: #666666;
  line-height: 23px;
  margin: 20px 0 14px;
}
.d-txt{
  font-weight: bold;
  font-size: 14px;
  color: #333333;
  line-height: 20px;
}
.d-imgs{
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-start;
  .d-img{
    width: 70px;
    height: 70px;
    margin-right: 14px;
    img{
      width: 100%;
      height: 100%;
      border-radius: 6px;
    }
  }
}
.b-title{
  font-size: 15px;
  color: #333333;
  line-height: 23px;
}
::v-deep .b-steps{
  display: flex;
  justify-content: flex-start;
  align-items: center;
  .u-line-1,.u-steps__item__text--column{
    span{
      font-weight: bold;
      font-size: 15px;
      color: #333333 !important;
      line-height: 21px;
    }
  }
}
.b-s-item-l{
  width: 98px;
}
.b-s-item-c,.b-s-item-r{
  width: calc(100% - 178px);
  view{
    font-size: 14px;
    color: #666666;
    line-height: 20px;
    margin-bottom: 43px;
    height: 20px;
    text{
      font-size: 12px;
      color: #666666;
      line-height: 12px;
      margin-left: 10px;
    }
  }
  view:last-child{
    margin-bottom: 0;
  }
}
.b-s-item-r{
  width: 80px;
  text-align: right;
  view.active{
    font-weight: bold;
    font-size: 14px;
    color: #1C7AF7;
    line-height: 14px;
  }
}
.nav-footer{
  width: 100%;
  height: 49px;
  display: fixed;
  bottom: 0;
  right: 0;
  left: 0;
  background: #fff;
  overflow: hidden;
  border-top: 0.5px #DDDDDD solid;
}
.item-footer{
  width: 50%;
  font-size: 13px;
  color: #333333;
  line-height: 13px;
  text-align: center;
  float: left;
  img{
    width: 20px;
    height: 20px;
    display: block;
    margin: 5px auto 6px;
  }
}
</style>
